﻿using System;
using LitJson;

public partial class Admin_Pages_viNews_News_NewsController : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["NewsId"] != null)
            SaveNews();
    }

    private void SaveNews()
    {
        int NewsId = 0;
        if (Int32.TryParse(Request.QueryString["NewsId"], out NewsId))
        {
            if (NewsId == 0)
            {
                // add a new news
                string jsonHtmlEncoded = Request.Params["data"];
                if (string.IsNullOrEmpty(jsonHtmlEncoded))
                    return;
                string json = Server.HtmlDecode(jsonHtmlEncoded);
                NewsData newsData = JsonMapper.ToObject<NewsData>(json);

                string selCATEGORY = "";
                if (string.IsNullOrEmpty(newsData.Category))
                    selCATEGORY = "-1";
                else
                {
                    string[] str = newsData.Category.Split(',');
                    if (Convert.ToInt32(str[1]) == 0)
                        selCATEGORY = str[0]; // Parent Only
                    else
                        selCATEGORY = str[1];// Child Only
                }
            }
            else if (NewsId > 0)
            {
                // update existing news
            }

        }
    }

    private class NewsData
    {
        private string _NewsId;
        public string NewsId { get { return _NewsId; } set { _NewsId = value; } }

        private string _Category;
        public string Category { get { return _Category; } set { _Category = value; } }

        private string _Author;
        public string Author { get { return _Author; } set { _Author = value; } }

        private string _Date;
        public string Date { get { return _Date; } set { _Date = value; } }

        private string _Publish;
        public string Publish { get { return _Publish; } set { _Publish = value; } }

        private string _Title;
        public string Title { get { return _Title; } set { _Title= value; } }

        private string _Summary;
        public string Summary { get { return _Summary; } set { _Summary = value; } }

        private string _Description;
        public string Description { get { return _Description; } set { _Description = value; } }

        private string _ImageAttachmentUrl;
        public string ImageAttachmentUrl { get { return _ImageAttachmentUrl; } set { _ImageAttachmentUrl = value; } }

        private string _Tags;
        public string Tags { get { return _Tags; } set { _Tags = value; } }
    }
}
